#ifndef _IO_CONNECTOR_H
#define _IO_CONNECTOR_H

#include "io_handler.h"
#include <boost/function.hpp>

class IoConnector : public IoHandler
{
public:
	typedef boost::function<void(const tcp::endpoint&, IoConnector*, const boost::system::error_code&)> ConnetionCallBack;

private:
	boost::asio::deadline_timer connectionTimer_;
	bool isConnected_;
	bool isTimeOut_;
	ConnetionCallBack err_, connected_;
	void connectTimeOut(const boost::system::error_code&);
	void onConnectionReturned(const boost::system::error_code& err);

public:
	IoConnector(boost::asio::io_service& service) : IoHandler(service), connectionTimer_(service), isConnected_(false), isTimeOut_(false) {}
	void startConnect(unsigned int timeout, const tcp::endpoint& addr, ConnetionCallBack err,
		ConnetionCallBack connected);
};

#endif
